<?php
function init_connect_db()
{
    //Initialisation of the conntion to the database.
	$db = mysql_connect('localhost', 'group5', '6unHehKP');
	if (!$db) {
    	print('Could not connect: '.mysql_error());
    	exit();
    }
    //Selection of the database "group5".
	if (!mysql_select_db("group5")) {
		printf('Could not open: '.'group5 table');
		exit();
	}
	return $db;
}

function get_title_places()
{
    //Get all title and id from places and return the result.
	$query = mysql_query("SELECT title,id FROM Places");
	if (!$query) {
		printf('Could not execut the query');
		exit();
	}
	return $query;
}

function get_content_places_from_id($id)
{
    //Get the content of a place from the id of this place and return the result.
	$temp = "SELECT * FROM Places WHERE id = '".addslashes($id)."'";
	$query = mysql_query($temp);
	if (!$query) {
		printf('Could not execut the query');
		exit();
	}
	return $query;
}

function get_comments_from_place($place)
{
    //Get all the comments attached to the place $place and return the result.
	$query = mysql_query("SELECT * FROM Comments WHERE Places_id = '".addslashes($place)."'");
	if (!$query) {
		printf('Could not execut the query');
		exit();
	}	
	return $query;
}

function get_user_from_id($id_user)
{
    //Get all info from the user who have $id_user as id and return the result.
        $query = mysql_query("SELECT * FROM Users WHERE id = '".addslashes($id_user)."'");
        if (!$query) {
                printf('Could not execut the query');
                exit();
        }
        return $query;
}

function get_dos_donts_city($type)
{
    //Get the list of the all the cities in dos or dont (according to $type) and return the result.
	$query = mysql_query("SELECT DISTINCT city FROM Tips WHERE type = '".addslashes($type)."'");
	if (!$query) {
		printf('Could not execut the query');
		exit();
	}
	return $query;
}

function get_all_dos_donts_city()
{
    //Get the list of the all the cities in dos or dont (according to $type) and return the result.
	$query = mysql_query("SELECT DISTINCT city FROM Tips");
	if (!$query) {
		printf('Could not execut the query');
		exit();
	}
	return $query;
}

function get_dos_donts_city_type($city, $type)
{
    //Get all the dos or dont (according to $type) from the city $city and return the result.
	$query = mysql_query("SELECT * FROM Tips WHERE city = '".addslashes($city)."' AND type = '".addslashes($type)."'");
	if (!$query) {
		printf('Could not execut the query');
		exit();
	}
	return $query;
}

function get_dos_donts_from_id($id)
{
    //Get tips from $id and return the result.
	$temp = "SELECT * FROM Tips WHERE id = '".addslashes($id)."'";
	$query = mysql_query($temp);
	if (!$query) {
		printf('Could not execut the query');
		exit();
	}

	return $query;
}

function get_faqs()
{
    //Get all the faqs and return the result.
	$query = mysql_query("SELECT question, id FROM Faqs");
	if (!$query) {
		printf('Could not execut the query');
		exit();
	}
	return $query;
}

function get_answer_faq_from_id($question_id)
{
    //Get the content of the faq from his id $question_id and return the result.
	$temp = "SELECT * FROM Faqs WHERE id = '".addslashes($question_id)."'";
	$query = mysql_query($temp);
	if (!$query) {
		printf('Could not execut the query');
		exit();
	}
	return $query;
}

?>